<template>
  <el-row class="report-header">
    <el-col :span="12">
      <!-- 日销售统计 -->
      <div class="home-user-task-stats bgc1 box">
        <div class="header">
          <div class="title">日销售统计</div>
        </div>
        <div class="body">
          <div
            v-for="(item, index) in dailySalesList"
            :key="index"
            class="stats"
          >
            <div class="item">
              <div class="num color1 text-shadow1">{{ item.count }}</div>
              <div class="text color2">{{ item.text }}</div>
            </div>
          </div>
        </div>
      </div>
    </el-col>
    <el-col :span="12">
      <!-- 月销售统计 -->
      <div class="home-sku-sale-stats bgc2 box">
        <div class="header">
          <div class="title">月销售统计</div>
        </div>
        <div class="body">
          <div
            v-for="(item, index) in monthlySalesList"
            :key="index"
            class="stats"
          >
            <div class="item">
              <div class="num color3 text-shadow2">{{ item.count }}</div>
              <div class="text color4">{{ item.text }}</div>
            </div>
          </div>
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import {
  getOrderCountAPI,
  getOrderAmountAPI,
  getTotalBillAPI
} from '@/api/reconciliation'
import {
  monthDetailEnd,
  dateDetailStart,
  monthDetailStart
} from '@/utils/dayjs'
export default {
  name: '',
  components: {},
  props: {},
  data() {
    return {
      // 日销售统计初始数据
      daySales: 0,
      daySaleroom: 0,
      dayDividedInto: 0,
      // 月销售统计初始数据
      monthSales: 0,
      monthSaleroom: 0,
      monthDividedInto: 0
    }
  },
  computed: {
    // 日销售统计页面最终渲染
    dailySalesList() {
      return [
        { text: '当日销售量（个）', count: this.daySales },
        { text: '当日销售额（元）', count: this.daySaleroom },
        { text: '当日分成（元）', count: this.dayDividedInto }
      ]
    },
    // 月销售统计页面最终渲染
    monthlySalesList() {
      return [
        { text: '当月销售量（个）', count: this.monthSales },
        {
          text: '当月销售额（元）',
          count: (this.monthSaleroom / 100).toFixed(2)
        },
        {
          text: '当月分成（元）',
          count: (this.monthDividedInto / 100).toFixed(2)
        }
      ]
    }
  },
  watch: {},
  async created() {
    await this.getDayCount()
    await this.getMonthCount()
  },
  methods: {
    // 获取一定时间范围之内的订单总数
    async getOrderCount(params) {
      try {
        const { data } = await getOrderCountAPI(params)
        return data
      } catch (error) {
        console.log(error)
      }
    },
    // 获取一定时间范围之内的收入
    async getOrderAmount(params) {
      try {
        const { data } = await getOrderAmountAPI(params)
        return data
      } catch (error) {
        console.log(error)
      }
    },
    // 获取一定时间范围之内的分成总数
    async getTotalBill(params) {
      try {
        const { data } = await getTotalBillAPI(params)
        return data
      } catch (error) {
        console.log(error)
      }
    },
    // 获取当日销售统计
    async getDayCount() {
      // 销售量
      this.daySales = await this.getOrderCount({ start: dateDetailStart, end: monthDetailEnd })
      // 销售额
      this.daySaleroom = await this.getOrderAmount({ start: dateDetailStart, end: monthDetailEnd })
      // 分成
      this.dayDividedInto = await this.getTotalBill({ start: dateDetailStart, end: monthDetailEnd })
    },
    // 获取当月销售统计
    async getMonthCount() {
      // 销售量
      this.monthSales = await this.getOrderCount({ start: monthDetailStart, end: monthDetailEnd })
      // 销售额
      this.monthSaleroom = await this.getOrderAmount({ start: monthDetailStart, end: monthDetailEnd })
      // 分成
      this.monthDividedInto = await this.getTotalBill({ start: monthDetailStart, end: monthDetailEnd })
    }
  }
}
</script>

<style scoped lang='scss'>
.report-header {
  margin-bottom: 20px;
  .box {
    padding: 20px;
    border-radius: 20px;
  }
  .header {
    display: flex;
  }
  .home-user-task-stats {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    height: calc(20vh - 24px);
    min-height: 166px;
    background: #e9f3ff;
    border-radius: 20px;
  }
  .bgc1 {
    background: #e9f3ff;
    background-image: url(~@/assets/bgtask.png), url(~@/assets/task.png);
    background-repeat: no-repeat, no-repeat;
    background-position: 0 0, calc(100% - 12px) 100%;
    margin-right: 10px;
  }
  .home-sku-sale-stats {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    height: calc(20vh - 24px);
    min-height: 166px;
    background: #e9f3ff;
    border-radius: 20px;
  }
  .bgc2 {
    background: #fbefe8 url(~@/assets/sale.png) no-repeat calc(100% - 12px) 100%;
    margin-left: 10px;
  }
  .title {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    font-size: 16px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333;
  }
  .body {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
  }
  .stats {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
  }
  .num {
    height: 50px;
    font-size: 36px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    line-height: 50px;
    text-shadow: 2px 4px 7px rgb(85 132 255 / 50%);
  }
  .color1 {
    color: #072074;
  }
  .text-shadow1 {
    text-shadow: 2px 4px 7px rgb(85 132 255 / 50%);
  }
  .text {
    height: 17px;
    margin-top: 3px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #91a7dc;
    line-height: 17px;
  }
  .color2 {
    color: #91a7dc;
  }
  .text-shadow2 {
    text-shadow: 2px 4px 7px rgb(255 99 85 / 50%);
  }
  .color3 {
    color: #ff5757;
  }
  .color4 {
    color: #de9690;
  }
  .item {
    display: inline-flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    flex-direction: column;
  }
}
</style>
